package com.mlt.back.dao.impl;

import com.mlt.back.beans.Brand;
import com.mlt.back.beans.Category;
import com.mlt.back.dao.CategoryDao;
import com.mlt.back.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public List<Category> selectAll() {
        List<Category> categoryList=new ArrayList<>();
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            conn= DBUtil.getConnection();
            String sql="select category_id,category_name,category_icon,category_status from t_category";
            ps=conn.prepareStatement(sql);
            rs=ps.executeQuery();
            while (rs.next()){
                Category category=new Category();
                category.setCategory_id(rs.getInt("category_id"));
                category.setCategory_name(rs.getString("category_name"));
                category.setCategory_icon(rs.getString("category_icon"));
                category.setCategory_status(rs.getString("category_status"));
                categoryList.add(category);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(conn,ps,rs);
        }
        return categoryList;
    }
}
